package com.danco.training.zaneuskaya.repository.impl;


import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.danco.training.zaneuskaya.domain.Account;
import com.danco.training.zaneuskaya.repository.AccountDao;
/**
 * @author Zaneuskaya Aliaksandra
 *
 */
@Repository
public class AccountDaoImpl extends AbstractHibernateDao<Account, Integer> implements AccountDao{


	
	private static final String PASSWORD_ACCOUNT = "password";
	private static final String EMAIL = "email";

	public Account read(Integer PK) throws HibernateException {
		return super.read(Account.class, PK);
	}

	@Override
	public List<Account> readAll() throws HibernateException {
		return super.readAll(Account.class,EMAIL);
		
	}

	@Override
	public Account login(String email, String password)throws HibernateException {
		Criteria criteria = getSession().createCriteria(Account.class);
		criteria.add(Restrictions.eq(EMAIL, email));
		criteria.add(Restrictions.eq(PASSWORD_ACCOUNT, password));
		return (Account) criteria.uniqueResult();
	}

	@Override
	public Account findAccountByLogin(String email) throws HibernateException{
		Criteria criteria = getSession().createCriteria(Account.class);
		criteria.add(Restrictions.eq(EMAIL, email));
		return (Account) criteria.uniqueResult();
	}

	

	

	

	
	
}
